package com.qk.management.controller;

import com.qk.code.BusinessEnum;
import com.qk.exception.LoginException;
import com.qk.management.service.UserService;
import com.qk.result.Result;
import com.qk.vo.common.LoginResultVO;
import com.qk.entity.User;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;
/**
 * @Author:zhengbowen
 * @Date: 2025/10/10 19:36
 * @Description: 登录控制器
 */
@Slf4j
@RestController
@RequiredArgsConstructor
public class LoginController {

    private  final UserService userService;

    @PostMapping("/login")
    public Result login(@RequestBody User user) {
        LoginResultVO loginResult = userService.login(user.getUsername(), user.getPassword());
        if (loginResult != null) {
            return Result.success(loginResult);
        } else {
            throw new LoginException(BusinessEnum.USER_NOT_LOGIN);
        }
    }
}